
void init_hw (void)
{
//============== Tmer 0 settings ==================================
#if ((1 == __BUILD_TYPE__) || (2 == __BUILD_TYPE__))
  #if (0 == TMR0_16B)
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_64|RTCC_8_BIT);//RTCC_DIV_128!!! 
  #else
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);//RTCC_DIV_128!!!
  #endif
#elif (3 == __BUILD_TYPE__)
  #if (0 == TMR0_16B) 
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_64|RTCC_8_BIT);//RTCC_DIV_128!!! 
  #else
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);//RTCC_DIV_128!!!
  #endif
    setup_timer_0(RTCC_OFF);
#else
#error !!! Not defined build !!!
#endif
//============================ TIMER1 SETUP ====================
#if ((1 == __BUILD_TYPE__) || (2 == __BUILD_TYPE__))
    setup_timer_1(T1_INTERNAL|TDIV);
#elif (3 == __BUILD_TYPE__)
	setup_timer_1(T1_DISABLED);
#else
#error !!! Not defined build !!!
#endif
//============== Tmer 3 settings ==================================
    set_timer3(-62500);
    setup_timer_3(T3_INTERNAL|RT_TMR_DIV); // T3 runing max time 0,104856 ms
    enable_interrupts(INT_TIMER3);

//============== Ports direction ===================================
    port_b_pullups(TRUE);
    PORTA = 0x00;
    buzz = 1;                   //off
#if ((1 == __BUILD_TYPE__) || (3 == __BUILD_TYPE__))
    set_tris_a(0b11001111);      //RA0 - RA4 analog in
    set_tris_b(0b00110000);      //RB 5&4 IN
    //   SET_TRIS_B(0b00100000);      //RB &5 IN
    INJ_CLOSE;
    COIL_OFF;

    //SET_TRIS_C(0b11000000);     //0-out 1-in, old
    set_tris_c(0b11011000);     //new

    // PORTA = 0x00;
    PORTC = 0x00;
#elif (2 == __BUILD_TYPE__)
    set_tris_a(0b11101111);     //0-out 1-in
    set_tris_c(0b11111101);     //0-out 1-in
    set_tris_b(0b11111111);     //0-out 1-in
    set_tris_e(0b11111111);     //0-out 1-in
    set_tris_d(0x00);           //0-out 1-in

    en_out_a = en_out_b = 0;    // enable driver A and B

    LATC = 0x00;
    LATD = 0x00;
#else
#error !!! Not defined build !!!
#endif
//============================ ADC SETUP =======================
//      ADCON0 = 0b10000001;   //Tac 1:32 bit7,6 adc-on bit0 3-5 bit analog chanel
//      ADCON1 = 0b00000010;   //8-bit res im ADRESH, RA0->RA4 analog in other digital
#if  ((1 == __BUILD_TYPE__) || (3 == __BUILD_TYPE__))
    setup_adc_ports(AN0_TO_AN3|VSS_VDD);
//setup_adc(ADC_CLOCK_DIV_32|ADC_TAD_MUL_16); //32/16
    setup_adc(ADC_CLOCK_DIV_64|ADC_TAD_MUL_20); //32/16
//       read_adc(adc_start_only);
#elif (2 == __BUILD_TYPE__)
    setup_adc(ADC_CLOCK_DIV_64|ADC_TAD_MUL_20); //32/16
    setup_adc_ports(AN0_TO_AN9);
#else
#error !!! Not defined build !!!
#endif

//============================ CCP SETUP =======================
//        CCP1CON =0b00001010;
#if ((1 == __BUILD_TYPE__) || (2 == __BUILD_TYPE__))
    CCP_1= us_to_tmr1_ticks(TRIGGER_FILTER);
    setup_ccp1(CCP_COMPARE_INT);
    CCP_2= ms_x_10_to_tmr1_ticks(in_parm.max_spk_dur);
    setup_ccp2(CCP_COMPARE_INT);
#endif

//++++++++++++++ Variables init ++++++++++++++++++++++++++++
//compiler init variables workaround
#if ((1 == __BUILD_TYPE__) || (3 == __BUILD_TYPE__))
    freeze_dispaly = 1;
    display_mode   = FUEL_MY;
#endif

#if (3 != __BUILD_TYPE__)
    pulse_crank    = 0;
    pw_count       = 0;
    f_count        = 0;

    //last_k_pa = last_tps = 0;
    //pw_acc_last = acc_timer = pw_acc = 0;
#endif

    return;
}


void enable_all_ints (void)
{
//============== INTERRUPTS_SETUP =======================
#if (3 != __BUILD_TYPE__)
        enable_interrupts(INT_TIMER1|INT_AD);
        enable_interrupts(INT_RDA);
        enable_interrupts(INT_OSCF);
        enable_interrupts(GLOBAL|INT_RB); // |INT_RDA
#else
        //enable_interrupts(INT_TIMER1|INT_AD);
        enable_interrupts(INT_RDA);
        //enable_interrupts(INT_OSCF);
        enable_interrupts(GLOBAL/*|INT_RB*/); // |INT_RDA
        enable_interrupts(INT_SSP);
#endif
}

